package com.akeil.flash.action;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import com.akeil.flash.dataprocessing.IConstantProcessor;
import com.akeil.flash.model.EDeviceStatusType;
import com.akeil.flash.pojo.Parameter;
import com.akeil.flash.preferences.IPreferenceConstants;
import com.akeil.flash.service.IParameterService;
import com.akeil.flash.service.ParameterServiceImpl;
import com.akeil.flash.view.ResultView;

import flash.Activator;
import flash.Application;

public class StartTestAction extends AbstractFlashAction {
	IParameterService parameterService = Application.applicationContext.getBean(ParameterServiceImpl.class);
	List<Byte> cmds = new ArrayList<Byte>();
	List<Object> datas = new ArrayList<Object>();
	
	public StartTestAction(){
		this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/start_32px.png"));
		this.setToolTipText(resourceBundle.getString("toolbar.start.test.tooltip"));
		this.setText(resourceBundle.getString("toolbar.start.test.name"));
	}
	
	@Override
	public void run() {
		// TODO Auto-generated method stub
		super.run();
		cmds.clear();
		datas.clear();
		List<Parameter> parameters = parameterService.selectAll();

		cmds.add(IConstantProcessor.SettingTemp);
		datas.add(parameters.get(0).getPretemperature().floatValue());
		
		cmds.add(IConstantProcessor.DelayTemp);
		datas.add(parameters.get(0).getNexttemperature().floatValue());
		
		cmds.add(IConstantProcessor.TestStep);
		datas.add(parameters.get(0).getMethod().equals("A") ? new Float(0) : new Float(1));
		
		cmds.add((byte)IConstantProcessor.SttFX);
		datas.add(new Float(0));
		
		if(cmds != null && cmds.size() > 0){
			Application.processor.sendParameters(cmds,datas);
		}
		
		//Application.processor.sendCommand((byte)IConstantProcessor.SttFX);
		ResultView resultView = (ResultView)PlatformUI.getWorkbench().getActiveWorkbenchWindow(). getActivePage().findView(ResultView.ID);
		resultView.readyTest();
		Application.flashData.setStatus(EDeviceStatusType.READY);
		
		Application.flashData.setReceived(false);
	}
}
